package com.dushibao.manage.login;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

@WebServlet("/logOut")
public class LogOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.getSession().removeAttribute("user");

        Cookie userNameCookie = new Cookie("userName", URLEncoder.encode("", "UTF-8"));
        Cookie passwordCookie = new Cookie("password",URLEncoder.encode("","UTF-8"));

        userNameCookie.setMaxAge(0);
        passwordCookie.setMaxAge(0);

        resp.addCookie(userNameCookie);
        resp.addCookie(passwordCookie);

        resp.sendRedirect("/login");

    }
}
